import {createRouter, createWebHistory} from 'vue-router';
import {routes} from './routes';
import {afterEach, beforeEach} from "./guard";

const router = createRouter({
	history: createWebHistory(import.meta.env.BASE_URL),
	routes: routes,
	// 滚动行为
	scrollBehavior(to, from, savedPosition) {
		// 返回 savedPosition，在按下 后退/前进 按钮时，就会像浏览器的原生表现那样
		if (savedPosition) {
			return savedPosition;
		}
		return {top: 0};
	},
})
router.beforeEach(beforeEach);
router.afterEach(afterEach);
export default router
